POV-Ray : Newsgroups : povray.beta-test : Doc Error for mod? : Re: Doc Error for mod? Server Time
30 Jul 2024 10:17:52 EDT (-0400)
  Re: Doc Error for mod?  
From: Jérôme Grimbert
Date: 23 Nov 2001 09:32:57
Message: <3BFE5E76.B3090531@atosorigin.com>
"Bob H." wrote:

> > >so long as
> > > int() rounds down anyway.
> >
> > Dependant on what you call down.
> > int keeps only the integer part. So,it's really down for positive numbers,
> > but it's a kind of up for negative numbers ( int(-2.8) = -2 ).
> > The formula given in the doc is fine using int() as it probably is
> > derived from the coding.
> 
> I see, but maybe you meant int(-2.5) would be -2 but I'd expect -2.8 to
> become -3.  I only meant from 0.5, 1.5, 3.5, etc. would go toward 0.  Not
> so?

No. 
int stand for "integer part". So int(2.99999999) is still 2, even if
it is dam close to 3.
(Ok, 2. and an infinity of 9 is really 3, but computer have a problem
with handling infinity that always I surprise me :-).

You're thinking of the 'nearest integer' rounding, which can be done with
int() too:  near(a) = int(a+0.5)
(And still, some may want to round x.5 toward x rather than x+1,
so it can still provide more discussion about using int or floor or ceil
 [because of the different rounding direction for positive/negative]).

> 
> > There is usually a catch with modulo operation with negative numbers,
> > at least in most computer implementation. I did not test the resulting
> value
> > for:
> >
> >   mod(-3,2)
> >   mod(3,-2)
> >   mod(-3,-2)
> >
> > But I suspect they give some negative values as most langage do.
> 
> Scientific calculator says yes.  Respectively: +1, -1, -1.

YMMV, according to the library used, so beware when having negative numbers.
 (or when comparing results)

> 
> Bob H.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.